package com.laogao.lesson084.article;

import com.laogao.lesson084.common.BusinessExceptionUtils;
import com.laogao.lesson084.dto.ArticlePublishRequest;
import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.atomic.AtomicInteger;

/**
 * 发布次数校验器，每日限制5篇文章
 * <b>description</b>： Java进阶、性能优化实战案例100讲，微信公众号:程序员恰恰，源码 & 文档 & 技术支持，请加个人微信号：it3306 <br>
 * <b>time</b>：2025/5/10 20:15 <br>
 * <b>author</b>：ready lao_gao
 */
@Slf4j
public class PublishCountCheck4 extends AbstractCheck {
    AtomicInteger publishCount = new AtomicInteger(0);

    @Override
    protected void checkIn(ArticlePublishRequest req) {
        log.info("发布次数检测执行完成!");
        if (publishCount.incrementAndGet() > 5) {
            //发布次数校验，比如每日只允许发布5篇文章
            throw BusinessExceptionUtils.businessException("今日发布已满，请明日继续分享！");
        }
    }
}
